package test03;

public class Student implements Comparable<Student>{
    public String name ;
    public int age;
    public double score;

    public Student(String name, int age, double score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }
    public static void sort(Comparable[] array){
        for (int i = 0; i < array.length -1; i++) {
            for (int j = 0; j < array.length - 1-i; j++) {
                if(array[j].compareTo(array[j+1]) > 0){
                    Comparable temp = array[j];
                    array[j] = array[j+1];
                    array[j+1] = temp;
                }
            }
        }
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        if (this.age > o.age) {
            return 1;
        } else if(this.age < o.age){
            return -1;
        } else {
            return 0;
        }
    }
}
